package com.qyt.hotel.service.impl;

import com.qyt.hotel.dao.RoomTypeMapper;
import com.qyt.hotel.entity.RoomType;
import com.qyt.hotel.entity.RoomTypePrice;
import com.qyt.hotel.service.RoomTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoomTypeServiceImpl implements RoomTypeService {

    @Resource
    private RoomTypeMapper roomTypeMapper;

    @Override
    public List<RoomType> getRoomTypeList() {
        return roomTypeMapper.getRoomTypeList();
    }

    @Override
    public RoomType getOne(RoomType roomType) {
        return roomTypeMapper.getOne(roomType);
    }

    @Override
    public Integer deleteRoomType(RoomType roomType) {
        // 当删除数据时还需查看有没有该房间类型有没有被使用
        Integer count = roomTypeMapper.getRoomTypeByUse(roomType.getRoomTypeId());
        if (count != null) {
            // 如果查到有数据就表示不能进行删除
            return null;
        } else {
            return roomTypeMapper.deleteRoomType(roomType);
        }

    }

    @Override
    public Integer addRoomType(RoomType roomType) {
        return roomTypeMapper.addRoomType(roomType);
    }

    @Override
    public Integer updateRoomType(RoomType roomType) {
        return roomTypeMapper.updateRoomType(roomType);
    }

    @Override
    public List<RoomTypePrice> statisticsRoomTypePrice() {
        return roomTypeMapper.statisticsRoomTypePrice();
    }
}
